<template>
  <div class="point-index">
    <div class="bg">
      <div class="top">
        <nuxt-link
          class="text"
          :to="'/' + enterpriseId + '/point/list/'"
          tag="h4"
          >我的积分</nuxt-link
        >
        <h2 class="point">{{ this.pointInfo.integral }}</h2>
        <div class="earn">
          <div>赚积分</div>
        </div>
      </div>
    </div>


    <div class="container">
      <div class="menu">
        <div
          class="item item1"
          @click="goPointShop"
        >
          <img src="../../../static/point/shangcheng.png" alt="" />
          <span>积分商城</span>
        </div>
        <nuxt-link
          class="item item2"
          :to="'/' + enterpriseId + '/point/bill'"
          tag="div"
        >
          <img src="../../../static/point/mingxi.png" alt="" />
          <span>积分明细</span>
        </nuxt-link>
        <nuxt-link class="item item3" :to="'/' + this.enterpriseId +'/point/list'" tag="div">
          <img src="../../../static/point/dingdan.png" alt="" />
          <span>积分订单</span>
        </nuxt-link>
      </div>
      <div
        class="news"
        @click="goPointShop"
      >
        <span class="title">积分商城上线啦！</span>
        <span class="des">多重好礼等着你</span>
      </div>
      <div class="show">
        <product-list  :sid="selectedStation.stationId" :showType="(selectedStation&&selectedStation.integralRule&&selectedStation.integralRule.showType)||1"/>
      </div>
    </div>

    <van-action-sheet
      v-model="stataionShow"
      :actions="stationActions"
      @select="onStationSelect"
      @close="stataionSelectClose"
    />
  </div>
</template>

<script>
import ProductList from "@/components/ProductList";
import { mapState, mapActions } from "vuex";
import Vue from "vue";
import { ActionSheet  } from "vant";
Vue.use(ActionSheet);

export default {
  head() {
    return {
      title: "积分主页",
    };
  },
  data() {
    return {
      images: [],
      list: [],
      loading: false, //加载状态
      finished: false, //是否完成加载
      refreshing: false, //是否正在上拉刷新
      stataionShow: false,
      stationActions: [],
      selectedStation: {},
    };
  },
  components: {
    ProductList,
  },
  computed: {
    ...mapState({
      pointInfo: (state) => state.point.pointInfo,
    }),
  },
  created(){
    if(this.phone){
      this.init();
      this.getPointInfo();
    }
  },
  methods: {
    ...mapActions({
      getPointInfo: "point/getPointInfo",
    }),
    init(){
        this.$axios
        .$get("/selectStaInfoList", {
          params: {
            enterpriseId: this.enterpriseId,
          },
        })
        .then((res) => {
          // console.log("axios", res);
          if (res.retCode === 0) {
            if (!!res.data) {
              this.stationActions = res.data.map((ele) => {
                return { ...ele, name: ele.stationName };
              });
              this.stationActions = [...this.stationActions];

              if(this.stationActions.length == 1){
                this.selectedStation = this.stationActions[0];
                this.stataionShow = false;
              }else{
                this.stataionShow = true;
              }
              // console.log(this.stationActions);
            }
          }
        });
    },
    onStationSelect(q) {
      this.selectedStation = q;
      this.stataionShow = false;
      console.log(q);
    },
    goPointShop(){
      console.log('go','/' + this.enterpriseId + '/point/shop/' + this.selectedStation.stationId + "/");
      this.$router.push({
        path:'/' + this.enterpriseId + '/point/shop/' + this.selectedStation.stationId + "/"+`?showType=${this.selectedStation.integralRule.showType||1}`
      })
    },
    stataionSelectClose(){
      if(!this.selectedStation.stationId){
        this.stataionShow = true;
      }
    }
  },
};
</script>

<style>
.point-index {
  position: relative;
}
.point-index .bg {
  background-color: #f3b335;
  width: 7.5rem;
  height: 3.72rem;
  position: relative;
  background: url("../../../static/point/bj.png") no-repeat 0px 0px;
  background-size: 100% 100%;
  z-index: -1;
}
.point-index .bg .top .text {
  position: absolute;
  left: 4vw;
  top: 8vw;
  margin: 0;
  padding: 0;
  height: 0.4rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;

  line-height: 0.4rem;
}
.point-index .bg .top .point {
  position: absolute;
  margin: 0;
  padding: 0;
  left: 4vw;
  top: 15.33vw;
  width: 36vw;
  height: 16.8vw;
  font-size: 12vw;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  line-height: 14vw;
}
.point-index .bg .earn {
  position: absolute;
  right: 0;
  top: 20.66vw;
  width: 1.6rem;
  height: 0.55rem;
  font-size: 3.46vw;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  background: url("../../../static/point/jifen.png") no-repeat;
  background-size: cover;
  box-sizing: border-box;
}
.point-index .bg .earn div {
  position: absolute;
  top: 1.5vw;
  right: 2vw;
  height: 4.93vw;
  font-size: 3.46vw;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #f3b235;
  line-height: 4.93vw;
}
.point-index .container {
  margin-top: -13.33vw;
  width: 100%;
  padding: 0 4vw;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  z-index: 99;
}
.point-index .container .menu {
  width: 6.9rem;
  height: 1.9rem;
  background: #ffffff;
  box-shadow: 0px 2px 10px 5px rgba(227, 227, 227, 0.5);
  border-radius: 20px;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  align-items: center;
  text-align: center;
}
.point-index .container .menu .item {
  width: 1.12rem;
}
.point-index .container .menu .item img {
  display: inline-block;
  width: 0.9rem;
  height: 0.9rem;
  margin: 0 auto;
}
.point-index .container .menu .item span {
  display: inline-block;
  font-weight: 400;
  color: #666666;
  text-align: center;
  margin-top: 0.2rem;
  height: 0.4rem;
  font-size: 0.26rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #666666;
  line-height: 0.4rem;
}

.point-index .container .news {
  margin-top: 0.3rem;
  width: 6.9rem;
  height: 1.6rem;
  background: url("../../../static/point/banner.png") no-repeat;
  background-size: 100% 100%;
  position: relative;
}
.point-index .container .news img {
  width: 100%;
  height: 100%;
}
.point-index .container .news .title {
  font-size: 0.4rem;
  color: #f9f9e5;
  font-weight: 700;
  position: absolute;
  left: 0.75rem;
  top: 0.38rem;
}
.point-index .container .news .des {
  font-size: 0.24rem;
  color: #f9d996;
  font-weight: 600;
  position: absolute;
  left: 2.2rem;
  top: 0.9rem;
}
</style>
